package action.chap7;

import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * @program: study-java8
 * @description:
 * @author: Sun Feng
 * @create: 2020-05-30 15:34
 **/
public class Test01 {
    public static void main(String[] args) {
        //这是一个全局设置，因此它将影响代码中所有的并行流。
       // System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism","500");
        long strat = Timestamp.valueOf(LocalDateTime.now()).getTime();
        List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9);
        ArrayList<Integer> arrayList = new ArrayList<>(numbers);
        for (int i = 10; i <100000 ; i++) {
            arrayList.add(i);
        }
        //21942
        //172114
        arrayList.stream().parallel()
                .forEach(s->{
                    System.out.println(Thread.currentThread().getName());
                    System.out.println(s);
                    try {
                        TimeUnit.MILLISECONDS.sleep(1);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                });
        long end = Timestamp.valueOf(LocalDateTime.now()).getTime();
        System.out.println(end-strat);
    }
}
